"--views
autocmd BufWinLeave * mkview                                         "save view/folding pattern
autocmd BufRead * silent! loadview                                   "load view/folding pattern

"--folding
autocmd BufEnter *.md setlocal foldmethod=expr
autocmd BufEnter *.md setlocal foldexpr=MarkdownLevel()              "custom folding for markdown files
autocmd BufEnter *.md setlocal foldtext=MyFoldText()                 "apply foldtext pattern

"----for these ft's, use 2 spaces for tab
autocmd FileType ruby,eruby,css,scss,javascript,js,yml,yaml set tabstop=2 shiftwidth=2 expandtab

"--omnicomplete engine
autocmd FileType php                setlocal omnifunc=phpcomplete#CompletePHP
autocmd FileType ruby,eruby         set omnifunc=rubycomplete#Complete
autocmd FileType html,xhtml         setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType css                setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType javascipt          setlocal omnifunc=js#CompleteJS

"--fugitive
autocmd BufReadPost fugitive://* set bufhidden=delete       "clean fugitive objs from buffers, thx Drew Neil

"--folding options for .tex files
autocmd BufEnter *.tex setlocal foldmethod=expr
autocmd BufEnter *.tex setlocal foldexpr=vimtex#fold#level(v:lnum)
autocmd BufEnter *.tex setlocal foldtext=vimtex#fold#text()

"--active window currentline highlight
augroup BgHighlight
    autocmd!
    autocmd WinEnter * set cursorline
    autocmd WinLeave * set nocursorline
augroup END

"--Mutt settings
autocmd BufNewFile,BufRead,BufEnter /tmp/neomutt* set filetype=mail
autocmd FileType mail            setlocal spell nocursorcolumn nohlsearch
"autocmd FileType mail            colorscheme murphy

"--TABLEMODE settings
augroup table_mode_on_mappings
  autocmd!
  autocmd User TableModeEnabled inoremap <CR> \|<CR>\||     "map CR to inesrt pipe on new line
  autocmd User TableModeEnabled nnoremap o o\||             "map o to new line and insert pipe on new line
  autocmd User TableModeEnabled inoremap <TAB> \||          "map tab TableMode to auto-insert a pipe
  autocmd User TableModeEnabled set tw=900|                 "set high tw to stop wrapping
augroup end
augroup table_mode_off_mappings
  autocmd!
  autocmd User TableModeDisabled iunmap <CR>
  autocmd User TableModeDisabled nunmap o
  autocmd User TableModeDisabled iunmap <TAB>
  autocmd User TableModeEnabled set tw=80|                           "set tw back to 80
augroup end

"--Goyo/Limelight
autocmd! User GoyoEnter Limelight                                                       
autocmd! User GoyoLeave Limelight!

"--assorted
autocmd FileType ruby nnoremap <leader>r :! clear &&  ruby %<CR>|    "execute ruby file and show output

autocmd FileType python set sw=4 ts=4 sts=4
